import { getStore } from '@/utils/store'

const userInfo = getStore('userInfo') || {}
export const formConfig = {
	inline: false,
	showBtn: true,
	labelPosition: 'top',
	labelWidth: '120px',
	column: [
		{
			label: '抽查规则名称',
			prop: 'spotRuleId',
			propName: 'spotRuleName',
			type: 'remoteSelect',
			api: 'view_omSpotRule_page',
			filterLabel: 'ruleName',
			filterKey: 'id',
			multiple: false,
			span: 12,
			rules: [{ required: true, message: '请输入抽查规则名称' }],
		},
		{
			label: '抽查批次名称',
			prop: 'batchName',
			maxlength: '50',
			showWordLimit: true,
			type: 'text',
			span: 12,
			rules: [{ required: true, message: '请输入抽查批次名称' }],
		},

		{
			label: '是否可重复抽查已抽查工单',
			prop: 'repeatOrderFlag',
			type: 'select',
			dicData: [
				{
					label: '否',
					value: 0,
				},
				{
					label: '是',
					value: 1,
				},
			],
			rules: [{ required: true, message: '请选择是否可重复抽查已抽查工单' }],
			span: 12,
		},
		{
			label: '是否可重复抽查已抽查老人',
			prop: 'repeatElderlyFlag',
			type: 'select',
			dicData: [
				{
					label: '否',
					value: 0,
				},
				{
					label: '是',
					value: 1,
				},
			],
			rules: [{ required: true, message: '请选择是否可重复抽查已抽查老人' }],
			span: 12,
			control: (e, model) => {
				return {
					repeatSpotBetween: {
						display: e == 1,
					},
				}
			},
		},
		{
			label: '某段已抽查时间内可重复抽查老人',
			prop: 'repeatSpotBetween',
			type: 'datetimerange',
			valueFormat: 'YYYY-MM-DD HH:mm:ss',
			span: 12,
		},
		{
			label: '抽查时间',
			prop: 'spotTimeBetween',
			type: 'datetimerange',
			valueFormat: 'YYYY-MM-DD HH:mm:ss',
			span: 12,
			rules: [{ required: true, message: '请选择抽查时间' }],
		},
		{
			label: '选择所属业务类型',
			prop: 'belongProject',
			type: 'remoteSelect',
			code: 'BELONG_PROJECT',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: false,
			span: 12,
			rules: [{ required: true, message: '请选择选择所属业务类型' }],
			control: (e) => {
				return {
					subprojectId: {
						display: ['govBuyManage', 'homeElderly', 'elderlyMeal', 'silverConsultant', 'familyNurseBed'].includes(e),
					},
				}
			},
		},
		{
			label: '选择对应业务的项目',
			prop: 'subprojectId',
			propName: 'subprojectName',
			api: userInfo.classifyId == 4 || userInfo.classifyId == 5 ? 'view_getOrgCooperateProjects' : 'view_omProjectCooperate_list',
			filterKey: 'projectId',
			filterLabel: 'projectName',
			span: 12,
		},
		{
			label: '类型',
			prop: 'spotType',
			type: 'select',
			dicData: [
				{
					label: '自动',
					value: 1,
				},
				{
					label: '人工',
					value: 2,
				},
			],
			control: (e) => {
				return {
					autoSpotDate: {
						display: e == 1,
					},
				}
			},
			rules: [{ required: true, message: '请选择类型' }],
			span: 12,
		},
		{
			label: '自动回访开始时间',
			prop: 'autoSpotDate',
			format: 'YYYY年MM月DD日',
			valueFormat: 'YYYY-MM-DD',
			type: 'date',
			span: 12,
			rules: [{ required: true, message: '请选择自动回访开始时间' }],
		},
	],
}

export const searchConfig = {
	inline: true,
	showBtn: true,
	labelPosition: 'left',
	column: [
		{
			label: '规则名称',
			prop: 'spotRuleName',
			type: 'input',
			span: 8,
		},
		{
			label: '批次名称',
			prop: 'batchName',
			type: 'input',
			span: 8,
		},
		{
			label: '所属业务类型',
			prop: 'belongProject',
			type: 'remoteSelect',
			code: 'BELONG_PROJECT',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: false,
			span: 8,
		},
		{
			label: '创建人',
			prop: 'createUserName',
			type: 'input',
			span: 8,
		},
		{
			label: '创建时间',
			prop: 'createTimeBetween',
			type: 'dateBetween',
			valueFormat: 'YYYY-MM-DD HH:mm:ss',
			span: 8,
		},
	],
}

export const tableSpotConfig = {
	stripe: true,
	border: true,
	columns: [
		{ label: '工单编号', prop: 'orderNo' },
		{ label: '所属区', prop: 'orgAreaName' },
		{ label: '所属街道', prop: 'orgStreetName' },
		{ label: '所属社区', prop: 'orgCommunityName' },
		{ label: '所属组织', prop: 'organizationName' },
		{ label: '老人姓名', prop: 'elderlyName' },
		{ label: '老人身份证号', prop: 'elderlyIdCard' },
		{ label: '工单时间', prop: 'startTime' },
	],
}

export const tableConfig = {
	stripe: true,
	border: true,
	columns: [
		{ label: '规则名称', prop: 'spotRuleName' },
		{ label: '批次名称', prop: 'batchName' },
		{
			label: '所属业务类型',
			prop: 'belongProject',
			custome: 'dict',
			code: 'BELONG_PROJECT',
		},
		{ label: '对应业务的项目', prop: 'subprojectName' },
		{
			label: '类型',
			prop: 'spotType',
			custome: 'tag',
			dicData: [
				{
					label: '自动',
					value: 1,
				},
				{
					label: '人工',
					value: 2,
				},
			],
		},
		{ label: '抽查时间', prop: 'spotTimeBetweenLabel' },
		{ label: '创建人', prop: 'createUserName' },
		{ label: '创建时间', prop: 'createTime' },
		{
			label: '操作',
			prop: 'menu',
			width: 300,
			fixed: 'right',
		},
	],
}

export const api = {
	index: 'view_omSpotBatch_page',
	add: 'view_omSpotBatch_add',
	edit: 'view_omSpotBatch_edit',
	delete: 'view_omSpotBatch_del',
	detail: 'view_omSpotBatch_one',
}
export const auth = {
	...api,
}
export const baseConfig = {
	pageName: '回访批次',
	dictcodes: ['BELONG_PROJECT'],
	rowKey: 'id',
	addLabel: '新增',
	tipLabel: 'batchName',
	exportMqTopic: '/ning/export/',
	api,
	auth,
	menuBtn: [
		{
			icon: 'editor',
			label: '抽查',
			type: 'primary',
			operate: 'spot',
			auth: auth.edit,
			condition: '(row)=>row.spotType ==2',
			text: true,
			show: true,
		},
		{
			icon: 'editor',
			label: '编辑',
			type: 'primary',
			operate: 'edit',
			auth: auth.edit,
			text: true,
			show: true,
		},
		{
			icon: 'delete',
			label: '删除',
			type: 'danger',
			operate: 'delete',
			auth: auth.delete,
			text: true,
			show: true,
		},
		{
			icon: 'detail',
			label: '详情',
			type: 'primary',
			operate: 'detail',
			auth: auth.index,
			text: true,
			show: true,
		},
	],

	saveFormate: async (form) => {
		return new Promise((resolve, reject) => {
			if (form.repeatSpotBetween) {
				form.repeatSpotStartTime = form.repeatSpotBetween[0]
				form.repeatSpotEndTime = form.repeatSpotBetween[1]
			}
			if (form.spotTimeBetween) {
				form.spotStartTime = form.spotTimeBetween[0]
				form.spotEndTime = form.spotTimeBetween[1]
			}
			resolve({
				...form,
				repeatSpotBetween: undefined,
				spotTimeBetween: undefined,
			})
		})
	},
	beforeOnLoadFormate: async (query) => {
		return new Promise((resolve, reject) => {
			resolve(query)
		})
	},
	onLoadFormate: async (arr) => {
		return new Promise((resolve, reject) => {
			resolve(
				arr.map((item) => {
					item.repeatSpotBetween = [item.repeatSpotStartTime, item.repeatSpotEndTime]
					item.spotTimeBetween = [item.spotStartTime, item.spotEndTime]
					item.spotTimeBetweenLabel = item.spotTimeBetween.toString()
					return {
						...item,
					}
				})
			)
		})
	},
	dialogConfig: {
		width: '75%',
	},
	searchConfig,
	formConfig,
	tableConfig,
	detailConfig: formConfig,
}
